package cn.sc.allinpay.allfavour.business.set;

import android.content.DialogInterface;
import android.content.Intent;

import java.util.ArrayList;
import java.util.List;

import cn.pai.common.listener.OnPromptListener;
import cn.pai.mvp.presenter.PaiPresenter;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.app.Constant;
import cn.sc.allinpay.allfavour.business.common.data.SetData;
import cn.sc.allinpay.allfavour.business.main.MainActivity;
import cn.sc.allinpay.allfavour.business.setsettle.SetSettleActivity;

/**
 * description：设置
 * author：pany
 * on 2018/10/24 10:04
 */
public class SetPresenter extends PaiPresenter<SetContract.View> implements SetContract.Presenter {

    private SetModel model = new SetModel();

    @Override
    public void start() {
        List<SetData> datas = new ArrayList<>();
        datas.add(new SetData("结算","settlement", R.mipmap.ic_set_settle));
        datas.add(new SetData("签退","loginOut", R.mipmap.ic_set_logout));
        datas.add(new SetData("参数设置","setconfig", R.mipmap.ic_set_config));
        datas.add(new SetData("收银员改密","cashierPwd", R.mipmap.ic_set_cashpwd));
        datas.add(new SetData("验券备注","checkRemark", R.mipmap.ic_set_remark));
        datas.add(new SetData("主管改密","managerPwd", R.mipmap.ic_set_magpwd));
        datas.add(new SetData("功能设置","serviceManage", R.mipmap.ic_set_config));
        view.adapterChange(datas);
    }

    @Override
    public void loginOut() {
        view.prompt(false, "您确定要退出登录吗?", new OnPromptListener("确定", "取消") {
            @Override
            public void onPositive(DialogInterface dialog, int which) {
                super.onPositive(dialog, which);
                dialog.dismiss();
                view.sendBroadcast(new Intent(Constant.Action.ACTION_CASHIER_LOGIN_OUT));
                view.finish();
            }

            @Override
            public void onNegative(DialogInterface dialog, int which) {
                super.onNegative(dialog, which);
                dialog.dismiss();
            }
        });
    }

    @Override
    public void settlement() {
        if (model.getGlobal().getPayInfo() != null) {
            view.prompt(false,"您有一笔订单状态未校正，请返回首页点击收银按钮校正", new OnPromptListener("确定") {
                @Override
                public void onPositive(DialogInterface dialog, int which) {
                    super.onPositive(dialog, which);
                    dialog.dismiss();
                    view.toActivity(MainActivity.class, null);
                    view.finish();
                }
            });
            return;
        }
       view.toActivity(SetSettleActivity.class,null);
    }
}
